import { EntityState } from "src/Ldz_GameCore/GeneralScripts/GameDefine";
import HoneyBeesBase from "src/Ldz_GameCore/HoneyBee/HoneyBeeManager/HoneyBeesBase";
import AnimatorTypeManager from "./AnimatorTypeManager";
import CombatantStateBase from "./CombatantStateBase";

//extends Laya.Script3D
export default class CombatantManageBase {

    public m_CurStateBase: CombatantStateBase = new CombatantStateBase();
    public states: Map<EntityState, CombatantStateBase> = new Map<any, CombatantStateBase>();//人物拥有的所有状态集合  字典 key=Type value=PlayerStateBase
    public m_SelfObj: Laya.Sprite3D;
    //public m_AttributeBase: SoldiersAttributeBase
    public m_SoldiersBase: HoneyBeesBase;


    InitManager(SelfObj: Laya.Sprite3D, SoldiersBase: HoneyBeesBase) {
        this.m_SelfObj = SelfObj;
        this.m_SoldiersBase = SoldiersBase;
    }

    public AddState(ScriptName: string)//where T: CombatantStateBase
    {
        if (AnimatorTypeManager.Instance.DoesTheTypeExist(ScriptName)) {
            let state: CombatantStateBase = this.m_SelfObj.addComponent(AnimatorTypeManager.Instance.GetTypeByName(ScriptName));//添加状态组件
            state.Init(this.m_SelfObj, this);//调用状态的初始化回调方法
            this.states.set(state.m_EntityState, state);//把状态添加到管理者的状态字典中
        }
    }

    public ChangeState(TempState: EntityState) // T: CombatantStateBase
    {
        //正在执行的状态调用退出状态的回调
        if (this.m_CurStateBase != null)
            this.m_CurStateBase.OnExit();
        //字典中获取需要切换到的状态对象 赋值给current
        this.m_CurStateBase = this.states.get(TempState);
        //console.log(this.m_CurStateBase.m_EntityState);
        if (this.m_CurStateBase != null) {
            this.m_CurStateBase.OnEnter();
        }
        //新状态调用进入状态的回调
    }
    onUpdate() {

        if (this.m_CurStateBase != null && this.IsUpdate)
            this.m_CurStateBase.OnExecute();
    }
    IsUpdate = true;
    public m_TargetObj: Laya.Sprite3D = null;


    public m_TargetObjWordPos: Laya.Vector3 = new Laya.Vector3();
    m_Attackinterval: number = 1;

    /**逻辑速度 */
    logicSpeed: Laya.Vector2 = Laya.Vector2.ZERO;
    /**转向 */
    renderDir: Laya.Quaternion = new Laya.Quaternion(0, 0, 0);
    /**zero */
    QuaternionZero: Laya.Quaternion = new Laya.Quaternion(0, 0, 0, 0);

}